<?php


namespace app\admin\controller;


use think\facade\View;

class Category extends AdminBase {
    public function jsonList() {
        try {
            $categoryList = (new \app\admin\business\Category())->getCategoryList();
        } catch (\Exception $e) {
            return show(config('status.error'), $e->getMessage());
        }
        return show(config('status.success'), '获得类型列表JSON成功', $categoryList);
    }

    public function modCategoryId() {
        if (!$this->request->isPost()) {
            return show(config('status.error'), '请求方式不对');
        }
        $categoryId = $this->request->param('categoryId', 0, 'intval');
        $ids = $this->request->param('ids');
        if (empty($categoryId) || empty($ids)) {
            return show(config('status.error'), '参数不对');
        }
        try {
            $res = (new \app\admin\business\Category())->modCategoryIdByIds($categoryId, $ids);
        } catch (\Exception $e) {
            return show(config('status.error'), $e->getMessage());
        }
        $result = ['back' => $res, 'categoryId' => $categoryId, 'ids' => $ids];
        if (empty($res)) {
            return show(config('status.error'), '修改类型失败', $result);
        }
        return show(config('status.success'), '修改类型成功', $result);
    }
}